﻿#ifndef LOGINSEMAPHORE_H
#define LOGINSEMAPHORE_H

#include "globalinstance.h"
#include <QMap>
#include <QString>
#include <QThread>

class QSystemSemaphore;

class LoginSemaphore : public QThread, public GlobalInstance<LoginSemaphore>
{
    Q_OBJECT
    friend class GlobalInstance<LoginSemaphore>;
    LoginSemaphore();
    ~LoginSemaphore() Q_DECL_OVERRIDE;
public:
    bool tryAcquire(int account_type, const QString &account);
    void cleanHandle();
    void cleanAll();
protected:
    void run() override;
private:
    void cleanRunning();
    QMap<QString, QSystemSemaphore *> semaphore_map;
    QSystemSemaphore *semaphore_;
};

#endif // LOGINSEMAPHORE_H
